#pragma once

#include "WriteVariableAction.h"

#include "InputPin.h"

namespace uml {

WriteVariableAction::WriteVariableAction(const QString& umlType)
    : VariableAction(umlType) {}

void WriteVariableAction::fromJson(const QJsonObject& json, QStringList& errorList) {
    if (json.isEmpty()) {
        return;
    }

    VariableAction::fromJson(json, errorList);
    value_ = JsonSerializable::create<InputPin>(json.value("value"), errorList);

}

void WriteVariableAction::toJson(QJsonObject& json) {
    VariableAction::toJson(json);
    if (value_) {
        QJsonObject value_json;
        value_->toJson(value_json);
        json.insert("value", value_json);
    }
}

/// <summary>
/// value getter
/// The InputPin that gives the value to be added or removed from the Variable.
/// </summary>
shared_ptr<InputPin> WriteVariableAction::value() const {
    return value_;
}

/// <summary>
/// value setter
/// The InputPin that gives the value to be added or removed from the Variable.
/// </summary>
void WriteVariableAction::setValue(shared_ptr<InputPin> value) {
    value_ = value;
}

} // namespace uml
